<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>天朝企业</title>
<%@include file="/view/common/js-css.jsp"%>
</head>
<body>
	<center>
		<h1>找回密码</h1><h4>${error }</h4>
	</center>
	<div class="container">
	<form class="form-horizontal" role="form"
		action="<%=request.getContextPath()%>/CompanyServlet?command=forgetPassword" method="post" onsubmit="return validate();">

		<div class="form-group">
		<label for="name" class="col-sm-2 control-label" style="margin-left:-80px;">e-mail/code</label>
			<div class="col-sm-10">
				<input type="text" class="form-control" name="email" placeholder="email" id="email">
			</div>
		<span id="emailInfo" class="bg-danger text-muted"></span></div>
		<div class="form-group">
			   请输入验证码：
			   <input type="text" name="verifyCode" id="verifyCode">
                    <img src="Kaptcha.jpg" onclick="changeVerifyCode()" id="yzmImg" style="cursor: pointer;">
                    <a href="javascript:void(0)" onclick="changeVerifyCode()">看不清，换一张</a>
			</div>
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10"">
				<button type="submit" class="btn btn-default">发送</button>
				
				 <input type="button" class="btn btn-primary" onclick="javascript:history.back();" value="返回"/>
			</div>
		</div>
	</form>
	<span class="label label-primary">${sendMailMsg }</span>
	</div>
	<script>
			/**
			 * 表单验证
			 */
			function validate() {
				var result = true;
				var code = document.getElementById("code");
				var email = document.getElementById("email");
				if(code.value == ''){
					document.getElementById("codeInfo").innerHTML="账号不能为空";
					result = false;
				}else{
					document.getElementById("codeInfo").innerHTML="";
				}
				if(email.value == ''){
					document.getElementById("emailInfo").innerHTML="邮箱不能为空";
					result = false;
				}else{
					document.getElementById("emailInfo").innerHTML="";
				}
				return result;
			}
			
			function changeVerifyCode(){
	            $("#yzmImg").attr("src","Kaptcha.jpg?"+Math.floor(Math.random()*100));
	        }
	        
	        //提交
	            function doSubmit() {
	            var verifyCodeValue = $("#verifyCode").val();
	            if(verifyCodeValue.replace(/\s/g,"") == "") {
	                alert("请输入验证码");
	            }else {
	                //提交前先异步检查验证码是否输入正确
	                var verifyUrl = "${pageContext.request.contextPath}/VerifyServlet?verifyCode="+verifyCodeValue;
	                $.ajax({
	                    type:"GET",
	                    url:verifyUrl,
	                    success:function(returnData){
	                        if(returnData!="Y") {
	                            alert("请输入正确的验证码！");
	                        }else {
	                            //验证码正确，进行提交操作
	                            alert("验证码输入正确");
	                        }
	                    },
	                    error:function(e){
	                        alert("输错了辣");
	                    }
	                });
	            }
	        }
			
			/**
			*el获取是否修改成功信息(相当于request.getParameter(arg0))
			*/
			if('${param.updateSuccess}'){
				layer.msg('发送成功！',{icon:1});
			}
			if('${param.updateError}'){
				layer.msg('发送失败！',{icon:0});
			}
			
		</script>
</body>
</html>